<?php

require_once '../../config.php';
require_once '../../functions.php';

$netbook = book_fetch_all("select * from netbook");

function add()
{
    if (empty($_POST['nick'])) {
        $GLOBALS['message']="请填写昵称的信息";
        return;
    }
    if (empty($_POST['content'])) {
        $GLOBALS['message']="请填写昵称";
        return;
    }
    $nick = $_POST['nick'];
    $content = $_POST['content'];
    $date = date('Y-m-d H:i:s', time());
    $row = book_execute("insert into netbook values (null,'{$nick}','{$content}','{$date}')");

    header('Location: /admin/users/netbook.php');
}

if ($_SERVER['REQUEST_METHOD']==='POST') {
    add();
}


?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Common &laquo; Admin</title>
    <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.min.css">

    <link rel="stylesheet" href="/static/assets/css/login_css.css">
    <link rel="stylesheet" href="/static/assets/css/base.css">
    <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
    <script src="/static/assets/vendors/jquery/jquery.min.js"></script>
    <script src="/static/assets/vendors/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
    <script src="/static/assets/vendors/nprogress/nprogress.js"></script>

    <style>
        .netbook {
            width: 1136px;
    border-radius: 5px;
    background-color: white;
    margin: 46px auto;
        }
        .look {
            width: 100%;
            height: 80px;
            text-align: center;
            line-height: 80px;
        }

        h2 {
            display: inline-block;
            font-family: "全新硬笔行书简";
            font-size: 45px;
        }

        .item {
            width: 100%;
            height:600px;
        }

        .flex {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .item ul {
            list-style-type: none;
            height: 90px;
            position: relative;
        }

        .item {
            padding: 20px 50px;
        }
        .item ul li:nth-child(1) {
            font-family: '华文行楷';
            font-size: 25px;
        }
        .item ul li:nth-child(2) {
            text-indent: 42px;
            font-family: "全新硬笔行书简";
            font-size: 25px;
        }
        .item ul li:nth-child(3) {
            position: absolute;
            right: 25px;
            bottom: 5px;
            font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
            user-select: none;
        }
    </style>
</head>

<body>
    <script>
        NProgress.start()
    </script>
    <!-- 导航栏 -->
    <?php include '../inc/navbar.php'; ?>

    <div class="container netbook">
        <div class="look">
            <h2>留言板</h2>
        </div>
        <form action="<?php $_SERVER['PHP_SELF']?>" method="post" style="padding: 10px 50px;">
            <div class="bs_common_remark">
                <h4>人生只有走出来的精彩，没有等出来的辉煌</h4>
                <div class="form-group">
                    <label for="content">留言</label>
                    <textarea class="form-control" name="content" id="content" cols="30" rows="3"></textarea>
                </div>
                <div class="flex">
                    <div class="form-group">
                        <label for="nick">昵称</label>
                        <input id="nick" class="form-control" name="nick" type="text" placeholder="昵称" value="">
                    </div>
                    <div class="form-group btn">
                        <button type="submit" class="btn btn-info">发布</button>
                    </div>
                </div>

        </form>
        <div class="item">
            <?php foreach ($netbook as $book):?>
                <ul>
                <li><?php echo $book['nick']?></li>
                <li><?php echo $book['content']?></li>
                <li><?php echo $book['date']?></li>
            </ul>
                <?php endforeach?>
           
            
        </div>
    </div>

    <script>
        $('.collapse').collapse()
    </script>
    <script>
        NProgress.done()
    </script>
</body>

</html>